import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

const state = {};

const getters = {};
const mutations = {};

const actions = {};

const modulesFiles = require.context('./modules', false, /\.js$/);
const modules = modulesFiles.keys().reduce((modules, modulePath) => {
  new RegExp(/^\.\/(.*)\.\w+$/).test(modulePath);
  const name = RegExp.$1;
  const module = modulesFiles(modulePath);
  modules[name] = module.default;
  return modules;
}, {});

export default new Vuex.Store({
  state,
  getters,
  mutations,
  actions,
  modules
});
